//
//  KZReviewSearchAndFilterView.m
//  lg_zhinengbeikao_english
//
//  Created by 朱凯 on 2019/1/7.
//  Copyright © 2019 zhukai. All rights reserved.
//

#import "KZReviewSearchAndFilterView.h"

@implementation KZReviewSearchAndFilterView
{
    UIButton *_filterButton;
    UITextField *_inputView;
}

- (instancetype)init {
    
    if (self = [super init]) {
        self.backgroundColor = UIColor.whiteColor;
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    _filterButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_filterButton setImage:[UIImage imageNamed:@"kz-筛选"] forState:UIControlStateNormal];
    [_filterButton setImage:[UIImage imageNamed:@"kz-筛选s"] forState:UIControlStateSelected];
    [_filterButton addTarget:self action:@selector(onTouchFilter) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_filterButton];
    [_filterButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(W(30));
        make.right.mas_equalTo(W(-15));
        make.bottom.mas_equalTo(H(-10));
    }];
    
    UIView *searchBgView = [UIView new];
    searchBgView.layer.cornerRadius = H(15);
    searchBgView.backgroundColor = kBgColor;
    [self addSubview:searchBgView];
    [searchBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(W(15));
        make.height.mas_equalTo(H(30));
        make.right.equalTo(self->_filterButton.mas_left).offset(W(-10));
        make.bottom.equalTo(self->_filterButton);
    }];
    
    UIImageView *searchIconView = [UIImageView new];
    searchIconView.image = [UIImage imageNamed:@"kz-放大镜"];
    [searchBgView addSubview:searchIconView];
    [searchIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(H(15));
        make.right.mas_equalTo(-W(15));
        make.centerY.equalTo(searchBgView.mas_centerY);
    }];
    
    _inputView = [UITextField new];
    _inputView.delegate = self;
    _inputView.placeholder = @"请输入试卷名称";
    _inputView.font = FONT(15);
    [searchBgView addSubview:_inputView];
    [_inputView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(searchIconView.mas_left).offset(W(-10));
        make.top.height.equalTo(searchBgView);
        make.left.mas_equalTo(W(10));
    }];
}

#pragma mark - setter
- (void)setIsInFilter:(BOOL)isInFilter {
    _isInFilter = isInFilter;
    _filterButton.selected = _isInFilter;
}

#pragma mark - 事件
- (void)onTouchFilter {
    
    [_inputView resignFirstResponder];
    if (_onTouchFilterCallback) {
        _onTouchFilterCallback();
    }
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    NSLog(@"2");
    
    return true;
}

@end
